//
//  MYAccount.m
//  奇闻
//
//  Created by 似水灵修 on 14-11-24.
//  Copyright (c) 2014年 MingYueGuCheng. All rights reserved.
//

#import "MYAccount.h"
@implementation MYAccount
- (void)setExpires_in:(NSString *)expires_in
{
    _expires_in = expires_in;
    //过期时间等于当前时间+expires_in
    NSDate *time = [NSDate date];
    _expires_time = [time dateByAddingTimeInterval:expires_in.longLongValue];
}
+ (instancetype)accountWithDict:(NSDictionary *)dict
{
    MYAccount *account = [[self alloc] init];
    if (account) {
        account.access_token = dict[MYAccessToken];
        account.expires_in = dict[MYExpiresIn];
        account.uid = dict[MYUid];
    }
    return account;
}
//解档
- (id)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super init]) {
        self.access_token = [aDecoder decodeObjectForKey:MYAccessToken];
        self.expires_in = [aDecoder decodeObjectForKey:MYExpiresIn];
        self.uid = [aDecoder decodeObjectForKey:MYUid];
        self.expires_time = [aDecoder decodeObjectForKey:MYExpiresTiem];
        self.name = [aDecoder decodeObjectForKey:MYName];
    }
    return self;
}
//归档
- (void)encodeWithCoder:(NSCoder *)aCoder
{
    [aCoder encodeObject:self.access_token forKey:MYAccessToken];
    [aCoder encodeObject:self.expires_in forKey:MYExpiresIn];
    [aCoder encodeObject:self.uid forKey:MYUid];
    [aCoder encodeObject:self.expires_time forKey:MYExpiresTiem];
    [aCoder encodeObject:self.name forKey:MYName];
}
@end
